<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: soft01
  Date: 21-10-14
  Time: 上午8:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>课程类别管理</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/back-index.css" />
    <script src="${pageContext.request.contextPath}/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap-paginator.js"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap-mypaginator.js"></script>
    <script type="text/javascript" charset="utf-8">
        $(function(){
            $("#doAddCourseType").on("click", function() {
                $(".modal-title").html("添加类别");
                $("#CourseType-id-input").hide();
                $("#courseTypeModal").modal("show");
            });
            $(".CourseType-btn").on("click", function() {
                $("#courseTypeModal").modal("hide");
            });

            $(".CourseType-modify").on("click", function() {
                $(".modal-title").html("修改类别");
                $("#CourseType-id-input").show();
                $("#courseTypeModal").modal("show");
            });

            //查询子类别
            $(".course-type-detail").on("click", function() {
                let parentId=$(this).attr("parentId");
                console.log(parentId);
                $('#frame-id', window.parent.document).attr('src', '${pageContext.request.contextPath}/courseType/findAllCourseType.do?parentId='+parentId);
            });
            //返回父类别列表页面
            $("#back").on("click", function() {
                let parentId= $("#parentId").attr("parentId");
                console.log(parentId);
                $('#frame-id', window.parent.document).attr('src', '${pageContext.request.contextPath}/courseType/backCourseType.do?id='+parentId);
            });
            $("#doAddCourseType").click(function () {//添加查找父课程
                let parentId= $("#parentId").attr("parentId");
                $("#d1").text("父课程：");
                console.log(parentId);
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath}/courseType/findCourseTypeById.do?id="+parentId,
                    dataType:"json",
                    success:function (result) {
                        if(result.responseCode=="2001"){
                            console.log("成功")
                            $("#addesg").text("");
                            $("#courseType-name").val("");
                            $("#courseType-id").val(result.returnObject.typeName)
                            $("#d123").attr("url","${pageContext.request.contextPath}/courseType/addCourseType.do?parentId="+parentId+"&typeName=");
                        }else{
                            console.log("失败")
                        }
                    }
                })
            })
            $("input[name='xiugai']").click(function () {//修改前查找类型的名字
                let parentId= $("#parentId").attr("parentId");
                let id=$(this).attr("TypeId1")
                console.log(id);
                $("#d1").text("编号：");
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath}/courseType/findCourseTypeById.do?id="+id,
                    dataType:"json",
                    success:function (result) {
                        if(result.responseCode=="2001"){
                            console.log("成功")
                            $("#addesg").text("");
                            $("#courseType-id").val(result.returnObject.id);
                            $("#courseType-name").val(result.returnObject.typeName);
                            $("#d123").attr("url","${pageContext.request.contextPath}/courseType/modifyCourseTypeById.do?parentId="+parentId+"&id="+result.returnObject.id+"&typeName=");
                        }else{
                            console.log("失败")
                            $("#addesg").text(result.message);
                        }
                    }
                })
            })
            $("#addType").click(function () {//添加或修改
                let parentId= $("#parentId").attr("parentId");
                let name=$("#courseType-name").val();
                console.log(parentId);
                console.log($("#d123").attr("url")+name)
                $.ajax({
                    type:"get",
                    url:$("#d123").attr("url")+name,
                    dataType:"json",
                    success:function (result) {
                        if(result.responseCode=="2001"){
                            console.log("成功")
                            $("#addesg").text("");
                            location.href="${pageContext.request.contextPath}/courseType/findAllCourseType.do?pageNo="+"${sessionScope.courseTypeList.pageNum}&parentId="+parentId;
                        }else{
                            console.log("失败")
                            $("#addesg").text(result.message);
                        }
                    }
                })
            })
            $("input[name='jinyong']").click(function () {//禁用
                let parentId= $("#parentId").attr("parentId");
                let id=$(this).attr("TypeId1")
                console.log(id);
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath}/courseType/yongCourseTypeById.do?status=-1&id="+id,
                    dataType:"json",
                    success:function (result) {
                        if(result.responseCode=="2001"){
                            console.log("成功")
                            $("#addesg").text("");
                            location.href="${pageContext.request.contextPath}/courseType/findAllCourseType.do?pageNo="+"${sessionScope.courseTypeList.pageNum}&parentId="+parentId;
                        }else{
                            console.log("失败")
                            $("#addesg").text(result.message);
                        }
                    }
                })
            })
            $("input[name='qiyong']").click(function () {//启用
                let parentId= $("#parentId").attr("parentId");
                let id=$(this).attr("TypeId1")
                console.log(id);
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath}/courseType/yongCourseTypeById.do?status=1&id="+id,
                    dataType:"json",
                    success:function (result) {
                        if(result.responseCode=="2001"){
                            console.log("成功")
                            $("#addesg").text("");
                            location.href="${pageContext.request.contextPath}/courseType/findAllCourseType.do?pageNo="+"${sessionScope.courseTypeList.pageNum}&parentId="+parentId;
                        }else{
                            console.log("失败")
                            $("#addesg").text(result.message);
                        }
                    }
                })
            })
            myoptions.pageUrl = function(type, page, current) {
                let parentId= $("#parentId").attr("parentId");
                return "${pageContext.request.contextPath }/courseType/findAllCourseType.do?pageNo="+page+"&parentId="+parentId;
            };
            myPaginatorFun("myPages",
                "${sessionScope.courseTypeList.pageNum==0?1:sessionScope.courseTypeList.pageNum}",
                "${sessionScope.courseTypeList.pages==0?1:sessionScope.courseTypeList.pages}");

        });
    </script>


</head>

<body>

<!-- 课程类别管理 -->
<div class="panel panel-default" id="departmentSet">
    <div class="panel-heading">
        <h3 class="panel-title">课程类别管理</h3>
    </div>
    <div class="panel-body">
        <input type="button" value="添加课程类别" class="btn btn-primary" id="doAddCourseType" /><span id="addesg" style="color: red"></span>
        <!-- courseType父类别id,没有时,移除此按钮 -->
        <input type="hidden" name="parent_id" value=""  />
        <c:choose>
            <c:when test="${sessionScope.parentId!='1'}">
        <input type="button" value="返回上级列表" class="btn btn-success" id="back" style="float: right;" />
            </c:when>
        </c:choose>
        <br>
        <br>
        <div class="modal fade" tabindex="-1" id="courseTypeModal">
            <!-- 窗口声明 -->
            <div class="modal-dialog modal-lg">
                <!-- 内容声明 -->
                <div class="modal-content">
                    <!-- 头部、主体、脚注 -->
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">添加类别</h4>
                    </div>
                    <span id="d123" url=""></span>
                    <div class="modal-body text-center">
                        <div class="row text-right" id="courseType-id-input" >
                            <label for="courseType-id" class="col-sm-4 control-label" id="d1">父课程：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="courseType-id" readonly="true" />
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label for="courseType-name" class="col-sm-4 control-label">类别名称：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="courseType-name" />
                            </div>
                        </div>
                        <br>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-primary courseType-btn" id="addType">确定</button>
                        <button class="btn btn-primary cancel" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="show-list">
            <table class="table table-bordered table-hover" style='text-align: center;'>
                <thead>
                <tr class="text-danger">
                    <th class="text-center">编号</th>
                    <th class="text-center">名称</th>
                    <th class="text-center">状态</th>
                    <th class="text-center">操作</th>
                </tr>
                </thead>
                <tbody id="tb">
                <span id="parentId" parentId="${sessionScope.parentId}"></span>
                <c:forEach items="${sessionScope.courseTypeList.list}" var="type" varStatus="i">
                <tr>
                    <td>${i.index+1}</td>
                    <td>${type.typeName}</td>
                        <c:choose>
                            <c:when test="${type.status==1}">
                                <td>启用</td>
                                <td>
                                    <input type="button" class="btn btn-warning btn-sm courseType-modify" name="xiugai" TypeId1="${type.id}" value="修改" />
                                    <input type="button" class="btn btn-danger btn-sm" name="jinyong" TypeId1="${type.id}" value="禁用" />
                                    <input type="button" class="btn btn-success btn-sm course-type-detail" parentId="${type.id}" value="查询子类别" />
                                </td>
                            </c:when>
                            <c:otherwise>
                                <td>禁用</td>
                                <td>
                                    <input type="button" class="btn btn-warning btn-sm courseType-modify" TypeId1="${type.id}" value="修改" />
                                    <input type="button" class="btn btn-success btn-sm" name="qiyong" TypeId1="${type.id}" value="启用" />
                                    <input type="button" class="btn btn-success btn-sm course-type-detail" parentId="${type.id}" value="查询子类别" />
                                </td>
                            </c:otherwise>
                        </c:choose>
                </tr>
                </c:forEach>
                </tbody>
            </table>
        </div>

        <!-- 分页 -->
        <div style="text-align: center;" >
            <ul id="myPages" ></ul>
        </div>
    </div>
</div>
</body>

</html>
